using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for AdminFormAdaptor.
	/// </summary>
	public class AdminFormAdaptor : Adaptor
	{
    private Action action;
    public AdminFormAdaptor(Action action)
    {
      this.action = action;
    }

    public override string Text
    {
      get
      {
        return action.Name;
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 3;
      }
    }

    public override Control GetRenderer()
    {
      AdminFormControl control = new AdminFormControl();
      control.LoadAction(action);
      return control;
    }

    public override void AddChildren(System.Windows.Forms.TreeNode node)
    {
      Map map = new Map(action.Server, action.MapName);
      FreeFlow.Administration.Form form = new FreeFlow.Administration.Form(action.Server, map.ProcedureName, action.Form);
      foreach (Field field in form.Fields)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new FieldAdaptor(field));
        node.Nodes.Add(childNode);
      }
    }

    public override object Object
    {
      get
      {
        return action;
      }
    }
	}
}
